#include "baseenemy.h"

#include <OgreEntity.h>
#include <stdio.h>
#include <OgreMath.h>
#include <OgreVector3.h>

BaseEnemy::BaseEnemy(World *world)
{
    m_world = world;
    m_speed = 500;
    m_lastShoot = m_world->getCurrentTime();
    m_health = 20;
    m_logger = Singleton::GetInstance();
}

void BaseEnemy::createModel(){
    Ogre::SceneManager * scene = m_world->getSceneManager();
    std::cout << getModel() << std::endl;
    Ogre::Entity* ogreHead = scene->createEntity(getModel());

    m_node = scene->getRootSceneNode()->createChildSceneNode();
    m_node->attachObject(ogreHead);

    m_node->yaw(Ogre::Degree(180));

    m_node->scale(1.3,1.3,1.3);
}

void BaseEnemy::setPosition(Ogre::Vector3 pos){
    m_node->setPosition(pos);
}

void BaseEnemy::destroy(){
    m_node->getParent()->removeChild(m_node);
    delete m_node;
}

void BaseEnemy::colide(AI *object){
    if((object->getType() == TYPE_BULLET || object->getType() == TYPE_FLAMER) && !object->isNpc()){
        m_health -= object->getDamage();
        if(m_health <= 0){
            m_world->removeActor(this);
        }
    }
}
